package controller

import (
	"pt-gin-mongo/constant/resCode"
	"pt-gin-mongo/error"
	"pt-gin-mongo/utils"

	"github.com/gin-gonic/gin"
)

type LoginParams struct {
	Key  string `json:"key"`
	Time string `json:"time"`
}

func login(c *gin.Context) {
	loginParams := LoginParams{}
	if err := c.ShouldBindJSON(&loginParams); err != nil {
		panic(&error.ApiError{Message: "参数错误", Code: resCode.Error})
	}

	if loginParams.Key == "panic" {
		panic(&error.ApiError{Message: "业务逻辑错误", Code: resCode.Error})
	}
	utils.ResponseOK(c, gin.H{"token": "abcdefg"})
}

func InitOpen(group *gin.RouterGroup) {
	router := group.Group("/open")

	router.POST("/login", login)
}
